<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="Stylesheet" href="css/style.css" type="text/css" />
<?php require_once("connection/connect.php");?>
<div class="content">
                <!-- content top -->
                <div class="content-top">
                    <div class="content-top-type">
                        <!-- item -->
                        <?php 
						
						//cho nay de random 5 sp
					$rs = mysql_query("select products.product_id as p1, pro_images.product_id as p2,pro_images.name as n1, products.name as n2 from products, pro_images WHERE products.product_id = pro_images.product_id order by rand() limit 5");
					while($d = mysql_fetch_array($rs)){
					?>
                        <table cellpadding="2px" style="float: left; width: 120px">
                            <tr>
                                <td>
                                    
                                        <img alt="" src="images/<?php echo $d['n1'];?>" width="120px" />
                                </td>
                            </tr>
                            <tr>
                                <td rowspan="2">
                                    <a href="category.php?id=<?php echo $d['p1'];?>"><?php echo $d['n2'];?></a>
                                </td>
                            </tr>
                        </table>
                        <?php }?>
                        <!-- /item -->
                        <div class="vide">
                        </div>
                    </div>
                </div>
                <!-- /content top -->
                <!-- category -->
                <div class="category">
                    <div class="title-3">
                        Danh mục hấp dẫn
                    </div>
                    <table cellpadding="5" cellspacing="0" style="width: 100%">
                        <tr>
                        <?php
						$numRow = 8;
						$rs = mysql_query("select * from categories");
						$numCol = ceil(mysql_num_rows($rs)/$numRow);
						for($col = 1; $col < $numCol + 1; $col++){
							echo "<td>";
							$x = ($col - 1)*$numRow;
							$rs = mysql_query("select * from categories limit ".$x.",".$numRow);	
							while($d = mysql_fetch_array($rs)){
								echo "<a href= category.php?id=".$d["cat_id"].">".$d["name"]."</a><br/>";
							}
							echo "</td>";
						}
						?>
                        </tr>
                    </table>
                    
                </div>
                <!-- /category -->
                <!-- Sàn nhà ở nổi bật -->
                <div class="content-center">
                    <div class="title-3">
                        Sànnhàở nổi bật
                    </div>
                    <!-- item -->
                    <?php //chọn 8 sản phẩm nổi bật do admin tự chọn
						$toTal = 8;
						$numCol = 2;
						$numRow = ceil($toTal / $numCol);
						for($i = 1; $i < $numRow + 1; $i++){			
							$t = ($i - 1)*$numCol;
							$rs = mysql_query("SELECT products.product_id as p1, products.name as n1, area, bedroom, bathroom, livingroom, hot,prices.product_id as p2, price, pro_images.product_id p3, pro_images.name as n2 FROM products, prices, pro_images WHERE prices.product_id = products.product_id AND products.product_id = pro_images.product_id AND hot = 1 limit ".$t.",".$numCol);
							$count = 1;
							$s = "left";
					?>
                    <div style="padding: 5px; border-bottom: 1px solid #d6d6d6">
					<?php
							while($d = mysql_fetch_array($rs)){
						?>
                        <table cellpadding="5px" style="float: <?php $count == 1 ? $s = "left" : $s = "right"; echo $s;?>">
                            <tr>
                                <td style="float: left; border: 3px solid #d6d6d6; padding: 3px">
                                    
                                        <img alt="" src="images/<?php echo $d['n2'];?>" width="115px" />
                                </td>
                                <td style=" <?php $count == 1 ? $s = "border-right: 1px solid #ff9900; width: 190px" : $s = "width: 190px"; echo $s; $count ++; ?>">
                                    <span class="text-5"><?php echo $d['n1'];?><br />
                                    </span><span class="text-1">$:</span> <?php echo number_format($d['price'],0);?> VND<br />
                                    <span class="text-1">Diện tích:</span> <?php echo $d['area'];?> m2<br />
                                    <span class="text-1">Phòng khách:</span> <?php echo $d['livingroom'];?><br />
                                    <span class="text-1">Phòng ngủ:</span> <?php echo $d['bedroom'];?><br />
                                    <span class="text-1">Phòng tắm:</span> <?php echo $d['bathroom'];?>
                                </td>
                            </tr>
                        </table>     
                        <?php }?>                   
                        <div class="vide">
                        </div>
						
                    </div>
                    <?php 
					}?>
                    <!-- /item -->
                </div>
                <!-- /Sàn nhà ở nổi bật -->
                <!-- Sàn nhà ở mới cập nhật -->
                <div class="content-center">
                    <div class="title-3">
                        Sànnhàở mới cập nhật
                    </div>
                    <!-- item 12 sp-->
                    <?php
						$toTal = 12;
						$numCol = 2;
						$numRow = ceil($toTal / $numCol);
						for($i = 1; $i < $numRow + 1; $i++){			
							$tmp = ($i - 1)*$numCol;
							$rs = mysql_query("
							SELECT products.product_id as p1, products.name as n1, products.provine_id, pro_images.product_id as p2, pro_images.name as n2, prices.product_id as p3, price, provines.provine_id, provines.name as n3
							FROM products, pro_images, prices, provines
							WHERE products.product_id = pro_images.product_id 
								AND products.product_id = prices.product_id 
								AND products.provine_id = provines.provine_id
							ORDER BY products.product_id desc limit ".$tmp.",".$numCol);
							$count = 1;							
					?>
                    <div style="padding: 5px; border-bottom: 1px solid #d6d6d6">
                        <!-- left item -->
                        <?php while($d = mysql_fetch_array($rs)){ ?>
                        <table cellpadding="5px" style="float: <?php $count == 1 ? $s = "left" : $s = "right"; echo $s;?>">
                            <tr>
                                <td style="float: left; border: 3px solid #ddd; padding: 3px">
                                    
                                        <img alt="" src="images/<?php echo $d['n2'];?>" width="60px" />
                                </td>
                                <td style=" <?php $count == 1 ? $s = "border-right: 1px solid #ff9900; width: 190px" : $s = "width: 245px"; echo $s; $count ++; ?>">
                                    <span class="text-5"><?php echo $d['n1'];?></span><br />
                                    <?php echo $d['n3'];?> - Giá: <?php echo number_format($d['price'],0);?> VND
                                </td>
                            </tr>
                        </table>
                        <?php }?>
                        <!-- /left item -->                       
                        <div class="vide">
                        </div>
                    </div>
                    <?php }?>
                    <!-- /item -->
                </div>
                <!-- /Sàn nhà ở mới cập nhật -->
            </div>